package liangtWorkSpace.bit;

/**
 * @ClassName BinaryString
 * @Description : 演示二进制演示转换
 * @Author : LiangT
 * @Date : 2020/8/28 10:05
 */
public class BinaryString {

    public static void main(String[] args) {
//        binary();

        binary2();


    }

    /**
     * 演示二、八、十、十六进制输出
     *
     */
    public static void binary(){
        //二进制
        int i = 0B101;
        System.out.println(i);
        System.out.println(Integer.toBinaryString(i));

        //八进制
        i = 0101;
        System.out.println(i);
        System.out.println(Integer.toBinaryString(i));

        //十进制
        i = 101;
        System.out.println(i);
        System.out.println(Integer.toBinaryString(i));

        //十六进制
        i = 0x101;
        System.out.println(i);
        System.out.println(Integer.toBinaryString(i));
    }

    /**
     * 演示二进制、八进制、十六进制之间转换
     */
    public static void binary2(){
         int i = 192;
        System.out.println("-----------------------");
        System.out.println("十转二："+Integer.toBinaryString(i));
        System.out.println("十转八："+Integer.toOctalString(i));
        System.out.println("十转十六："+Integer.toHexString(i));
        System.out.println("-----------------------");
        System.out.println("二转十："+Integer.valueOf("1100000",2).toString());
        System.out.println("二转十："+Integer.valueOf("300",8).toString());
        System.out.println("二转十："+Integer.valueOf("c0",16).toString());
        System.out.println("------------------------");
    }
}
